package com.leather.activity.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.leather.activity.mapper.ActivityGetMapper;
import com.leather.activity.service.ActivityService;
import com.leather.activity.vo.ActivityAddVo;
import com.leather.common.entity.ActivityGet;
import com.leather.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ActivityController {

    @Autowired
    private ActivityService activityService;
    @Autowired
    private ActivityGetMapper activityGetMapper;


    @GetMapping("index")
    public Result index(int pageId) {
        return activityService.index(pageId*20);
    }

    @PostMapping("judge")
    public Result judge(int activityId, int userId) {

        QueryWrapper<ActivityGet> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId).eq("activity_id", activityId);
        Integer count = activityGetMapper.selectCount(wrapper);
        return Result.success(count > 0);
    }

    @GetMapping("userindex")
    public Result userIndex(int userId) {
        return activityService.userIndex(userId);
    }

    @GetMapping("myactivity")
    public Result myActivity(int userId) {
        return activityService.userActivity(userId);
    }

    @PostMapping("delete")
    public Result delete(int activityId, int userId) {
        return activityService.deleteActivity(activityId, userId);
    }


    @PostMapping("addactivity")
    public Result addActivity(ActivityAddVo activityAddVo) {
        return activityService.addActivity(activityAddVo);
    }

    @PostMapping("getin")
    public Result getIn(int activityId, int userId) {
        return activityService.getIn(activityId, userId);
    }

    @GetMapping("getpassedlist")
    public Result getPassedList(int activityId){
        return activityService.getPassedList(activityId);
    }

}
